package com.sdp.core.bizc.vo;

import java.io.Serializable;

import com.sdp.core.bizc.utils.CoreConstantsEnum;

import lombok.Data;

@SuppressWarnings("serial")
@Data
public class Result<T> implements Serializable {

	/**
	 * 成功标志
	 */
	private boolean success = true;

	/**
	 * 返回处理消息
	 */
	private String message = "操作成功！";

	/**
	 * 返回代码
	 */
	private String code = "0";

	/**
	 * 返回数据对象 data
	 */
	private T result;

	/**
	 * 时间戳
	 */
	private long timestamp = System.currentTimeMillis();

	public Result() {

	}
	
	public Result<T> success(String message) {
		this.message = message;
		this.code = CoreConstantsEnum.系统执行成功代码.getCode();
		this.success = true;
		return this;
	}
	
	public static Result<Object> ok() {
		Result<Object> r = new Result<Object>();
		r.setSuccess(true);
		r.setCode(CoreConstantsEnum.系统执行成功代码.getCode());
		r.setMessage(CoreConstantsEnum.系统执行成功提示语.getCode());
		return r;
	}
	
	public static Result<Object> ok(String mes) {
		Result<Object> r = new Result<Object>();
		r.setSuccess(true);
		r.setCode(CoreConstantsEnum.系统执行成功代码.getCode());
		r.setMessage(mes);
		return r;
	}
	
	public static Result<Object> ok(Object data) {
		Result<Object> r = new Result<Object>();
		r.setSuccess(true);
		r.setCode(CoreConstantsEnum.系统执行成功代码.getCode());
		r.setResult(data);
		return r;
	}
	
	
	public static Result<Object> error() {
		Result<Object> r = new Result<Object>();
		r.setSuccess(false);
		r.setCode(CoreConstantsEnum.系统执行失败代码.getCode());
		r.setMessage(CoreConstantsEnum.系统执行失败提示语.getCode());
		return r;
	}
	
	public static Result<Object> error(String mes) {
		Result<Object> r = new Result<Object>();
		r.setSuccess(false);
		r.setCode(CoreConstantsEnum.系统执行失败代码.getCode());
		r.setMessage(mes);
		return r;
	}
	
	public static Result<Object> error(Object data) {
		Result<Object> r = new Result<Object>();
		r.setSuccess(false);
		r.setCode(CoreConstantsEnum.系统执行失败代码.getCode());
		r.setResult(data);
		return r;
	}

}
